home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / textwndw.swg / 0015_FAST Windowing Routines.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-08-24  |  7.8 KB  |  275 lines

  1. {
  2. Ok, here comes my window routines. They should be quite fast, and hopefully
  3. not too hard to understand. No range-checking on the screen coordinates is
  4. done (I don't think it's necessary).
  5.  
  6. The ColorAttr variable is the color-attribute :-). It's used as in the
  7. videomemory. If you want to call the procedure with a separate foreground
  8. and background color (why?), drop me a note and I'll fix it if you can't
  9. do it yourself.
  10.  
  11. It'll run on a 8086, and I don't want copies optimized with 286 code!
  12.  
  13. (if this message gets chopped for you -- too bad. Get it from a friend or
  14. tell someone to upload it to a BBS in the US if you want it. Use good
  15. mailing software!)
  16.  
  17. --------------------------------------------------->8-------------------------
  18.  
  19. { Window routines by Jens Larsson (Fido address, 2:201/2120.3), Sweden, PD. }
  20. { Feel free to use it in your own programs. But do credit me, will you? :-) }
  21. { Put it in SWAG if you like... }
  22.  
  23. {$M 1024,0,0}
  24. Uses Crt;
  25.  
  26. { The following variable should be assigned at startup to the correct segment }
  27. { address (b800h or b000h). I've posted a source for doing this before, thus  }
  28. { it's not included here. }
  29.  
  30.  Const TextVidSeg : Word = $b800;
  31.  
  32.    Var ScrBuf, Pdwns : Word;
  33.  
  34.       Function AllocMemory(Paragraphs : Word) : Word; Assembler;
  35.          Asm
  36.            mov   ax,4800h
  37.            mov   bx,Paragraphs  { Number of 16-byte chunks }
  38.            int   21h
  39.            jnc   @Done          { Ok? }
  40.            mov   ax,4c00h
  41.            int   21h            { If not, halt program! }
  42. @Done:
  43.          End;
  44.  
  45.       Procedure PullDown(x1, y1, x2, y2 : Word;
  46.                          FrameType,
  47.                          ColorAttr      : Byte;
  48.                          PDName         : String); Assembler;
  49.  
  50.         Var DeltaX, DeltaY, AddDI : Word;
  51.  
  52.          Asm
  53.            jmp   @CodeBegin    { Jump to the actual code }
  54.  
  55. { Ok Pascal-lovers... I'm sorry, but I declared the data like below...  }
  56. { Somehow it seemed easier to me (I guess I've used assembler too much) }
  57.  
  58. @Frame:
  59.  
  60. { This is all the ASCII codes for all the possible types of frames }
  61.  
  62.            db    020h,020h,020h,020h,020h,020h  { '      ' }
  63.            db    0dah,0c4h,0bfh,0b3h,0c0h,0d9h  { '┌─┐│└┘' }
  64.            db    0c9h,0cdh,0bbh,0bah,0c8h,0bch  { '╔═╗║╚╝' }
  65.            db    0d6h,0c4h,0b7h,0bah,0d3h,0bdh  { '╓─╖║╙╜' }
  66.            db    0d5h,0cdh,0b8h,0b3h,0d4h,0beh  { '╒═╕│╘╛' }
  67.  
  68. @FrameOfs:
  69.  
  70. { And this is the offsets to the above structures }
  71.  
  72.            db    000h,006h,00ch,012h,018h
  73.  
  74. @CodeBegin:
  75.            cmp   Pdwns,16      { Max pulldowns = 16 (16 * 4096 = 65536) }
  76.            jz    @Done
  77.  
  78.            cld
  79.  
  80. { Calculate start offset }
  81.  
  82.            mov   di,y1
  83.            dec   di
  84.            mov   ax,di
  85.            mov   cl,5
  86.            shl   di,cl
  87.            mov   cl,7
  88.            shl   ax,cl
  89.            add   di,ax
  90.            mov   ax,x1
  91.            dec   ax
  92.            add   ax,ax
  93.            add   di,ax
  94.  
  95.            mov   dx,di
  96.            add   dx,4    { This is the offset for the PutName part later }
  97.  
  98.            mov   ax,x2
  99.            sub   ax,x1
  100.            dec   ax
  101.            mov   DeltaX,ax
  102.            add   ax,2
  103.            mov   bx,80
  104.            sub   bx,ax
  105.            sub   bx,2
  106.            add   bx,bx
  107.            mov   AddDI,bx
  108.            mov   ax,y2
  109.            sub   ax,y1
  110.            dec   ax
  111.            mov   DeltaY,ax
  112.  
  113.            push  ds
  114.            push  di
  115.  
  116.            mov   si,di
  117.            mov   di,Pdwns
  118.            mov   cl,12
  119.            shl   di,cl         { Calculate offset in save segment }
  120.            mov   es,ScrBuf     { Save segment -> ES }
  121.            mov   ds,TextVidSeg
  122.            mov   es:[di],si    { Store offset to screen }
  123.            mov   bx,DeltaX
  124.            add   bx,4
  125.            mov   es:[di+2],bx  { Store DeltaX }
  126.            mov   cx,DeltaY
  127.            add   cx,3
  128.            mov   es:[di+4],cx  { Store DeltaY }
  129.            mov   ax,AddDI
  130.            mov   es:[di+6],ax  { Store AddDI }
  131.            add   di,8
  132. @SaveScreen:
  133.            push  cx
  134.            mov   cx,bx
  135.            rep   movsw         { Save line }
  136.            add   si,ax
  137.            pop   cx
  138.            dec   cx
  139.            jnz   @SaveScreen
  140.  
  141.            pop   di
  142.            pop   ds
  143.  
  144.            mov   es,TextVidSeg
  145.  
  146.            xor   bh,bh
  147.            mov   bl,FrameType
  148.            lea   si,@FrameOfs
  149.            add   si,bx
  150.            mov   bl,cs:[si]    { Get offset within frame data }
  151.            lea   si,@Frame
  152.            add   si,bx         { SI points to frame }
  153.  
  154.            mov   ah,ColorAttr
  155.            mov   al,cs:[si]
  156.            stosw               { Print upper-left corner }
  157.            mov   al,cs:[si+1]
  158.            mov   cx,DeltaX
  159.            rep   stosw         { Print horisontal line }
  160.            mov   al,cs:[si+2]
  161.            stosw               { Print upper-right corner }
  162.            add   di,AddDI
  163.            add   di,4
  164.  
  165.            push  ds
  166.  
  167.            xchg  dx,di         { Save DI }
  168.            mov   bx,si         { Save SI }
  169.            lds   si,PDName
  170.            mov   cl,[si]       { Get length of string }
  171.            xor   ch,ch
  172.            mov   ah,ColorAttr
  173.            inc   si
  174. @PutName:
  175.            lodsb               { Get next char }
  176.            stosw               { Print next name-char }
  177.            dec   cx
  178.            jnz   @PutName
  179.            mov   di,dx
  180.            mov   si,bx
  181.  
  182.            pop   ds
  183.  
  184.            mov   cx,DeltaY
  185. @PutWindow:
  186.            push  cx
  187.            mov   al,cs:[si+3]  { Get horisontal-line char }
  188.            stosw               { Print... }
  189.            mov   al,20h
  190.            mov   cx,DeltaX
  191.            rep   stosw         { Print some spaces }
  192.            mov   al,cs:[si+3]
  193.            stosw
  194.            mov   al,08h        { Shadow attribute (Bkgr = 0 Frgr = 8) }
  195.            inc   di
  196.            stosb               { Print first shaded char... }
  197.            inc   di
  198.            stosb               { ... and second }
  199.            add   di,AddDI
  200.            pop   cx
  201.            dec   cx
  202.            jnz   @PutWindow
  203.  
  204.            mov   al,cs:[si+4]
  205.            stosw               { Print lower-left corner }
  206.            mov   al,cs:[si+1]
  207.            mov   cx,DeltaX
  208.            rep   stosw
  209.            mov   al,cs:[si+5]
  210.            stosw               { Print lower-right corner }
  211.            mov   al,08h
  212.            inc   di
  213.            stosb
  214.            inc   di
  215.            stosb
  216.            add   di,AddDI
  217.            add   di,5
  218.  
  219.            mov   cx,DeltaX
  220.            add   cx,2
  221. @PutLastShadowLine:
  222.            stosb
  223.            inc   di
  224.            dec   cx
  225.            jnz   @PutLastShadowLine
  226.  
  227.            inc   Pdwns
  228. @Done:
  229.          End;
  230.  
  231.       Procedure RestoreScreen; Assembler;
  232.          Asm
  233.            cmp   Pdwns,0       { If no pulldowns then exit }
  234.            jz    @Done
  235.            cld
  236.            dec   Pdwns
  237.            mov   si,Pdwns
  238.            mov   es,TextVidSeg
  239.            push  ds
  240.            mov   ds,ScrBuf
  241.            mov   cl,12
  242.            shl   si,cl
  243.            mov   di,[si]       { Load offset to screen }
  244.            mov   bx,[si+2]     { Load DeltaX }
  245.            mov   cx,[si+4]     { ... DeltaY }
  246.            mov   dx,[si+6]     { ... AddDI }
  247.            add   si,8
  248. @PutText:
  249.            push  cx
  250.            mov   cx,bx
  251.            rep   movsw         { Restore line }
  252.            add   di,dx
  253.            pop   cx
  254.            dec   cx
  255.            jnz   @PutText
  256.            pop   ds
  257. @Done:
  258.          End;
  259.  
  260. { Short example program }
  261.  
  262.            Begin
  263.              ScrBuf := AllocMemory(4096);
  264.              TextBackground(4);
  265.              ClrScr;
  266.              PullDown(10,5,70,20,1,$1f,' Window #1 ');
  267.              ReadKey;
  268.              PullDown(5,10,60,22,2,$4e,' Window #2 ');
  269.              ReadKey;
  270.              RestoreScreen;
  271.              ReadKey;
  272.              RestoreScreen;
  273.            End.
  274.  
  275.